package com.theta.gateway.infra.common.exception.enums;

import com.theta.gateway.infra.common.utils.StrUtil;

import lombok.Getter;

@Getter 
public enum ErrorPatternEnum {
	
	SERVICE_UNAVAILABLE(503,"com.netflix.client.ClientException*available server*","服务不可用"),
	INSTANCE_NOT_FOUND(503,"*Unable to find instance*","请求的接口资源所属服务不可用"),
	INTERFACE_NOT_FOUND(404,"*NOT_FOUND*","请求的接口资源不存在"),
	INTERFACE_TIMEOUT(500,"*timed out*","接口资源请求超时"),
	
	;
	
	private int code;
	private String pattern;
	private String message;
	ErrorPatternEnum(int code,String pattern, String message) {
		this.code = code;
		this.pattern=pattern;
		this.message = message;
	}

	public int getCode() {
		return code;
	}

	public String getMessage() {
		return message;
	}
	
	public static ErrorPatternEnum getExceptionEnum(String message) {
		ErrorPatternEnum ee=null;
		if(StrUtil.isEmpty(message))return ee;
		for(ErrorPatternEnum e:ErrorPatternEnum.values()) {
			boolean isMatch=StrUtil.isMatchPattern(message, e.getPattern());
			if(isMatch) {
				ee=e;
				break;
			}
		}
		return ee;
	}

}
